<template>
  <div class="login-box">
    <div style="width: 400px; margin: 150px auto;">
      <el-card class="box-card" shadow="hover">

      <div
        style="
          color: #ccccc;
          font-size: 30px;
          text-align: center;
          padding: 30px 0;
          
        "
      >
        管理员登录
      </div>
      <el-form ref="form" :model="form" size="normal">
        <el-form-item>
          <el-input v-model="form.account" placeholder="请输入账号"></el-input>
        </el-form-item>
        <el-form-item>
          <el-input
            v-model="form.password"
            placeholder="请输入密码"
            show-password
          ></el-input>
        </el-form-item>

        <el-form-item>
          <el-button style="width: 100%" type="primary" @click="login"
            >登录</el-button
          >
        </el-form-item>
      </el-form>
      </el-card>
    </div>
  </div>
</template>

<script>
import request from "../../utils/request";
//import router from "@/router";
//import router from "@/router/index.js";

export default {
  name: "adminLogin",
  data() {
    return {
      form: {},
    };
  },
  mounted() {
    sessionStorage.removeItem("admin");
  },
  methods: {
    login() {
      request.post("/admin/login", this.form).then((res) => {
        console.log(res);
        if (res.code != "0") {
          this.$message({
            type: "error",
            message: "登录失败",
          });
        }
        this.$message({
          type: "success",
          message: "登录成功",
        });
        sessionStorage.setItem("admin", JSON.stringify(res.data)); //保存admin信息
        this.$router.push("/admin");
        console.log("执行结束");
      });
    },
  },
};
</script>

<style>
.login-box {
  background-image: url("../../assets/img/login/bg.jpg");
  background-repeat: no-repeat;
  background-size: 100% 100%;
  width: 100%;
  height: 100vh;
  overflow: hidden;
}
</style>